package com.atguigu.tingshu.order.service.impl;

import com.atguigu.tingshu.model.order.LocalMsg;
import com.atguigu.tingshu.order.mapper.LocalMsgMapper;
import com.atguigu.tingshu.order.service.MqOpsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MqOpsServiceImpl implements MqOpsService {

    @Autowired
    private LocalMsgMapper localMsgMapper;

    /**
     * 更新本地消息表
     * @param content
     */
    @Override
    public void updateLocalMsg(String content) {
        LambdaQueryWrapper<LocalMsg> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LocalMsg::getMsgContent, content);
        LocalMsg localMsg = localMsgMapper.selectOne(wrapper);
        // 如果找到匹配的消息，则更新其状态为1
        if (localMsg != null) {
            localMsg.setStatus(1);
            // 更新数据库中的消息记录
            localMsgMapper.updateById(localMsg);
        }
    }

}